387. First Unique Character in a String - LeetCode Solution


String Hash Table Queue

Python Code:

class Solution:
    def firstUniqChar(self, s: str) -> int:
        
        dic = {}
        
        for i in range(len(s)):
            if s[i] in  dic:
                dic[s[i]] = -2
            else:
                dic[s[i]] = i
        
        for i in dic:
            if dic[i] == -2:
                continue
            else:
                return dic[i]
        return -1


Comments

Submit
0 Comments
More Questions

1358B - Maria Breaks the Self-isolation
828A - Restaurant Tables
1735A - Working Week
1735D - Meta-set
1735B - Tea with Tangerines
1735C - Phase Shift
1321C - Remove Adjacent
281B - Nearest Fraction
1043A - Elections
1598C - Delete Two Elements
1400C - Binary String Reconstruction
1734D - Slime Escape
1499A - Domino on Windowsill
991A - If at first you don't succeed
1196C - Robot Breakout
373A - Collecting Beats is Fun
965A - Paper Airplanes
863E - Turn Off The TV
630E - A rectangle
1104A - Splitting into digits
19C - Deletion of Repeats
1550B - Maximum Cost Deletion
1693A - Directional Increase
735D - Taxes
989A - A Blend of Springtime
339C - Xenia and Weights
608A - Saitama Destroys Hotel
1342C - Yet Another Counting Problem
548A - Mike and Fax
109A - Lucky Sum of Digits